#include "memory.h"

static word memory [MEMORY_WORDS];
static unsigned int memory_index = 0;

int load_memory (word *buf, int size)
{
	if (size + memory_index > MEMORY_WORDS)
	{
		return -1;
	}
	memcpy (memory + memory_index, buf, size * sizeof (word));
	memory_index = memory_index + size;
	return 0;
}

int clear_memory (void)
{
	memory_index = 0;
	return 0;
}

word read_memory (word address)
{
	address = address & MEMORY_MASK;
	return memory [address];
}
void write_memory (word address, word data)
{
	address = address & MEMORY_MASK;
	memory [address] = data;
}

